import { defineStore } from 'pinia'
import { ref } from 'vue'
import { getUserAPI } from '@/apis/user'

export const useUserStore = defineStore('user', () => {
    // state
    let token = ref('')
    let userInfo = ref({})

    // action
    // 获取用户信息
    const getUserInfo = async () => {
        const res = await getUserAPI()
        console.log(res);
        userInfo.value = res.data
    }
    // 清空用户信息
    const clearUserInfo = () => {
        token.value = ''
        userInfo.value = {}
    }

    return {
        token,
        userInfo,
        getUserInfo,
        clearUserInfo,
    }
}, {
    persist: true,
})